<css>postcss相关配置

postcss做了什么

  1. postcss 将你的 css 文件转变成 JS 对象
  2. postcss 插件会遍历生成的js对象添加/删除/修改选择器或属性
  3. postcss 将该对象转换成 css 文件

webpack配置postcss

1
2
3
4
5
6
7
8
9
10
11
12
13
14
module.exports = {
module: {
rules: [
{
test: /\.css$/,
use: ['style-loader', 'postcss-loader'],
},
{
test: /\.jsx?$/,
use: ['babel-loader', 'astroturf/loader'],
}
]
}
}

常用postcss插件

autoprefixer

  • 添加浏览器前缀

postcss-import

postcss-url

postcss-plugin-px2rem

.postcssrc.js文件配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
module.exports = {
"plugins": {
"postcss-import": {},
"postcss-url": {},
"postcss-plugin-px2rem": {
//设计稿尺寸/10
rootValue: 37.5,
//屏蔽的属性
propBlackList: ['border'],
//屏蔽的路径
exclude: /src/,
},
"autoprefixer": {}
}
}